<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<body>
a
<script>
    var web3 = new Web3(Web3.givenProvider || "ws://localhost:7545");
    //获取区块号
    web3.eth.getBlockNumber().then(res=>{
        console.log(res)
    });
    //获取链id
    web3.eth.getChainId().then(res=>{
        console.log(res)
    });
    //获取余额
    web3.eth.getBalance("0xeE590c18e965f63e10F29e79be5B4672d5d5B68C").then(res=>{
        console.log(res)
        console.log(web3.utils.fromWei(res,"ether"))  //wei -> ether
    });
    //授权账号信息
    web3.eth.requestAccounts().then(res=>{
        console.log("授权",res)
        title.innerHTML =res[0]
    })
    //获取账号信息
    web3.eth.getAccounts().then(res=>{
        console.log(res)
    });
    //以太网单位需要换算，获取到的是wei单位  需要转换成ether ether=1e18 wei case给旷工的单位是Gwei
    //建议运算的时候 都转成wei 进行运算 只有在展示的时候才用ether
    //转钱
    web3.eth.sendTransaction({
        from:  title.innerHTML,
        to:'0x08938d0Bd229C8127dD37451b34672cc2B60E515',
        value:web3.utils.toWei("1","ether")
    }).then(function (receipt){
      console.log("转完了")
    });

</script>
</body>
</html>